/**
 * 例子：加深装饰器的使用能力
 */

{
	const userState = {
		username: 'Jimmy',
		isLogin: false,
	}
	const AccessCross = (
		target: Object,
		propertyKey: string | symbol,
		descriptor: PropertyDescriptor
	) => {
		const method = descriptor.value

		descriptor.value = () => {
			if (userState.isLogin) {
				method()
				return
			}
			console.log('请先登录后操作')
		}
	}

	class User {
		/**
		 * 保存文章需要登录才能操作
		 */
		@AccessCross
		public store() {
			console.log('保存文章')
		}
		public watch() {
			console.log('阅读文章')
		}
	}

	new User().store()
}
